package stalker.room;

import java.util.Calendar;
import java.util.GregorianCalendar;

import junit.framework.Assert;

import org.junit.Test;

import stalker.user.User;
import data.content.ContentSentence;

/**
 * JUnit for User.java and Catalog.java
 * @deprecated
 */

public class RoomTest {

  Room old_room;
  
  
  public void verifyOldRoom() {
    Assert.assertEquals("Room:getRoomID fail", old_room.getID(), 2L);
    Assert.assertEquals("Room:getName fail", old_room.getName(), "Listiarso Wastuargo");
    Assert.assertEquals("Room:toString fail", old_room.toString(), "Listiarso Wastuargo");
    Assert.assertTrue("Room:equals fail", old_room.equals(old_room));
    Assert.assertFalse("Room:equals fail", old_room.equals(null));
    Assert.assertFalse("Room:equals fail", old_room.equals((Integer)5));
    Assert.assertNotNull("Room:getDatas fail", old_room.getDatas());
    Assert.assertNotNull("Room:getRoomUsers fail", old_room.getRoomUsers());
    Assert.assertTrue("Room:getDatas fail", old_room.getDatas().isEmpty());
  }
  
  @Test
  public void testNewRoom() {
    Assert.assertFalse("Catalog:isTaken fails", Room.isTaken("Listiarso Wastuargo"));
    old_room = PrivatePersistentRoom.create("Listiarso Wastuargo");
    Assert.assertTrue("Catalog:isTaken fails", Room.isTaken("Listiarso Wastuargo"));
    Assert.assertEquals("Catalog:getRoom fails", old_room, Room.getRoomFromID(2L));
    verifyOldRoom();
    
    Calendar before = new GregorianCalendar();
    Room new_room = PrivatePersistentRoom.create("Irvan");
    Calendar after = new GregorianCalendar();
    Assert.assertEquals("Catalog:getRoom fails", new_room, Room.getRoomFromID(3L));
    Assert.assertEquals("Catalog:getRoom fails", old_room, Room.getRoomFromID(2L));
    Assert.assertTrue("Room:getCreationCalendar fail",
        new_room.getCreationCalendar().compareTo(before) >= 0);
    Assert.assertTrue("Room:getCreationCalendar fail",
        new_room.getCreationCalendar().compareTo(after) <= 0);
    Assert.assertEquals("Room:getRoomID fail", new_room.getID(), 3L);
    Assert.assertEquals("Room:getName fail", new_room.getName(), "Irvan");
    Assert.assertEquals("Room:toString fail", new_room.toString(), "Irvan");
    Assert.assertTrue("Room:equals fail", new_room.equals(new_room));
    Assert.assertFalse("Room:equals fail", new_room.equals(null));
    Assert.assertFalse("Room:equals fail", new_room.equals((Integer)5));
    Assert.assertFalse("Room:equals fail", new_room.equals(old_room));
    Assert.assertNotNull("Room:getDatas fail", new_room.getDatas());
    Assert.assertNotNull("Room:getRoomUsers fail", new_room.getRoomUsers());
    Assert.assertTrue("Room:getDatas fail", new_room.getDatas().isEmpty());
    new_room.getDatas().addData(User.createUser("Van"), new ContentSentence("Ganteng"));
    Assert.assertFalse("Room:getDatas fail", new_room.getDatas().isEmpty());

    verifyOldRoom();
  }

  @Test(expected=AssertionError.class)
  public void testRetryRoomname() {
    Room new_room = PrivatePersistentRoom.create("Listiarso Wastuargo");
    System.out.println(new_room);
  }
  
  @Test(expected=AssertionError.class)
  public void testNullName() {
    Room new_room = PrivatePersistentRoom.create(null);
    System.out.println(new_room);
  }
  
  @Test(expected=AssertionError.class)
  public void testOutOfRangeRoom() {
    Room room = Room.getRoomFromID(4L);
    System.out.println(room);
  }
  
  @Test(expected=AssertionError.class)
  public void testNegativeRoom() {
    Room room = Room.getRoomFromID(-1L);
    System.out.println(room);
  }

}
